package com.itcms.webservice;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import com.itcms.common.util.DateUtil;
import com.itcms.webservice.domain.Info;
import com.itcms.webservice.domain.Person;
import com.itcms.webservice.uuv.org.UUVOrgServicesSoap;

public class Test {
	public static void main(String[] args) throws MalformedURLException {
		URL wsdlURL = new URL("http://127.0.0.1:8080/itcms/webservice/infopubService?wsdl");
		QName SERVICE_NAME = new QName("http://impl.webservice.itcms.com/", "infopubService");
		Service service = Service.create(wsdlURL, SERVICE_NAME);
		InfopubService client = service.getPort(InfopubService.class);
		info(client);
	}
	
	public static void main1(String[] args) throws MalformedURLException {
		URL wsdlURL = new URL("http://172.16.84.20:32069/BiztalkESB/10002.asmx?wsdl");
	    QName SERVICE_NAME = new QName("http://tempuri.org/", "UUVOrgServicesSoap");
		Service service = Service.create(wsdlURL, SERVICE_NAME);
		UUVOrgServicesSoap client = service.getPort(UUVOrgServicesSoap.class);
		XMLGregorianCalendar beginLastUpdateDate = dateToXmlDate(DateUtil.getDate("2010-01-01", DateUtil.DATE_FORMAT));
		XMLGregorianCalendar endLastUpdateDate = dateToXmlDate(DateUtil.getDate("2017-04-24", DateUtil.DATE_FORMAT));
		System.out.println(client.getUUVLocalOrgList(beginLastUpdateDate, endLastUpdateDate)); 
	}
	private static void node(InfopubService client) {
		String result = client.getCategoryJson("gdjt2010");
		System.out.println(result);
	}
	
	/*private static void nodeList(InfopubService client) {
		List<NodeVo> result = client.getCategoryJson("");
		for (NodeVo nodeVo : result) {
			System.out.println(nodeVo.getCateName()+"-"+nodeVo.getLeve());
		}
	}*/
	
	private static void info(InfopubService client) {
		// TODO Auto-generated method stub
		String cateID = "101";
		String subCateIDs = "101,102,104";
		String content = "<p>这是test</p>";
		String expDate = "2017-02-21 14:46:00";
//		String filesJsoin = info.getFilesJsoin();
//		String lastUpdateDate = "2017-02-08 14:46:00";
//		String lastUpdateUserId = info.getLastUpdateUserId();
//		String lastUpdateUserName = info.getLastUpdateUserName();
		String publishedTime = "2017-02-08 14:46:00";
//		String siteID = "1";
		String source = "这是摘要";
//		String subTitle = info.getSubTitle();
//		String templateId = info.getTemplateId();
		String title = "这是title11";
//		String type = info.getType();
		String url = "www.baidu.com";
//		String writeDate = info.getWriteDate();
//		String writer = info.getWriter();
//		String writerName = info.getWriterName();
//		Info info = new Info(cateID, content, expDate, filesJsoin, lastUpdateDate, lastUpdateUserId, lastUpdateUserName, publishedTime, siteID, source, subTitle, templateId, title, type, url, writeDate, writer, writerName)
		Info info = new Info();
		info.setCateID(cateID);
		info.setSubCateID(subCateIDs);
		info.setContent(content);
		info.setPublishedTime(publishedTime);
		info.setExpDate(expDate);
		info.setSource(source);
		info.setTitle(title);
		info.setType("F");
//		info.setUrl(url);
		String result = client.infoSave(info, "gdjt2010");
		System.out.println(result);
	}
	
	/** 
     * 将Date类转换为XMLGregorianCalendar 
     * @param date 
     * @return  
     */  
    public static XMLGregorianCalendar dateToXmlDate(Date date){  
            Calendar cal = Calendar.getInstance();  
            cal.setTime(date);  
            DatatypeFactory dtf = null;  
             try {  
                dtf = DatatypeFactory.newInstance();  
            } catch (DatatypeConfigurationException e) {  
            }  
            XMLGregorianCalendar dateType = dtf.newXMLGregorianCalendar();  
            dateType.setYear(cal.get(Calendar.YEAR));  
            //由于Calendar.MONTH取值范围为0~11,需要加1  
            dateType.setMonth(cal.get(Calendar.MONTH)+1);  
            dateType.setDay(cal.get(Calendar.DAY_OF_MONTH));  
            dateType.setHour(cal.get(Calendar.HOUR_OF_DAY));  
            dateType.setMinute(cal.get(Calendar.MINUTE));  
            dateType.setSecond(cal.get(Calendar.SECOND));  
            return dateType;  
        }
}
